import axios from 'axios'
import cheerio from 'cheerio' // 帮助在服务端 查找dom元素

async function fetchUrl(url: string) {
  const res = await axios.get(url)
  const result = res.data;
  // console.log('result:', result)
  analysisHtml(result)
}

function analysisHtml(text: string) {
  const $ = cheerio.load(text);
  const groupCity = $('.group');
  // console.log('groupCity:', groupCity)
  const cityOpt = {}
  groupCity.map((index, el) => {
    // document.querySelector('') node 环境中没有document

    // let alpha = $(el).find('h6').text();
    let cityText = $(el).find('block').children()

    console.log('citys:', cityText)
    // cityText.map((i, v) => {
    //   console.log(i, v)
    //   console.log('-----:', $(v).text())
    // })
    // citys.map((item:any) => {
    //   console.log($(item).text())
    // })
    // console.log(citys, 'citys')
    // console.log('alpha:', alpha)
    // cityOpt[alpha]
  })
}

fetchUrl(`https://m.lianjia.com/city/`)
